﻿#include <qg/qg.h>

int main(void)
{
	k_mesg("TEXTURE TEST\n");

	qgDevice* dev = qgDevice::New(NULL, 640, 480, QGSDF_MSAA | QGSDF_LAYOUT);

	if (dev)
	{
		dev->Mount(QG_WORK_PATH);

		qgStub* stub = dev->GetStub();
		qgFreeType* font = qgFreeType::New();

		dev->SetBackground(tpl::ColorValue(0xFF604040));

		qgTexture* tex = dev->CreateTexture("/texture/z.png", QGTEXF_S2D);

		//
		float x = 0.0f, y = 0.0f;
		bool ok = false;

		while (dev->Run())
		{
			float spd = 200.0f;
			float adv = stub->GetAdvance();
			const tpl::Point& size = stub->GetSize();

			if (stub->IsKeyDown(QIK_UP))
				y -= spd * adv;
			if (stub->IsKeyDown(QIK_DOWN))
				y += spd * adv;
			if (stub->IsKeyDown(QIK_LEFT))
				x -= spd * adv;
			if (stub->IsKeyDown(QIK_RIGHT))
				x += spd * adv;

			x = k_clamp(x, 0.0f, (float)(size.x - 250));
			y = k_clamp(y, 0.0f, (float)(size.y - 250));

			dev->Enter();

			dev->DrawRect(tpl::Rect((int)x, (int)y, (int)x + 250, (int)y + 250), tpl::ColorValue(0xFFFFFFFF), tex);

			font->WriteFormat(5, 5, 0, "[%.2f]", stub->GetRunFps());

			dev->Leave();
			dev->Flush();
		}

		kobj_unload(tex);
		font->Unload();
		dev->Unload();
	}

	return 0;
}
